from flask import Blueprint, request
from flask_restful import Api, Resource, marshal_with
from flask_restful.reqparse import RequestParser

from utils.render import json_detail_render
from webapp.dto_mapper import leave_page_fields, room_page_fields, borrow_page_fields
from webapp.service.room_service import RoomService

wx_emptyroom_app = Blueprint('emptyroom', __name__, url_prefix='/wxapi/emptyroom')
wx_emptyroom_api = Api(wx_emptyroom_app)

parser = RequestParser()
parser.add_argument('id', location='json', type=int, trim=True, required=True)
parser.add_argument('uid', location='json', type=int, trim=True, required=False)

@wx_emptyroom_api.resource("", "/")
class LeaveWxApi(Resource):
    @marshal_with(room_page_fields)
    def post(self):
        data = request.get_json()
        return RoomService.findempty(jsonData=data)

@wx_emptyroom_api.resource("", "/apply")
class LeaveWxListApi(Resource):
    def post(self):
        data = request.get_json()
        return RoomService.applyResource(data)
@wx_emptyroom_api.resource("", "/applyList")
class LeaveWxApplyListApi(Resource):
    @marshal_with(borrow_page_fields)
    def post(self):
        return RoomService.applyList()